home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
mus
/
edit
/
AlgoRhythms.lha
/
AlgoRhythms
/
Source
/
musictimer.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-25
|
5KB
|
213 lines
/*MusicTimer.c
Copyright (c) 1990,1991,1992,1993 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
208A Olde Derby Road
Norwood, MA 02062-1761
(617)769-7733
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C Amiga Compiler 6.50
**
** ABSTRACT:
**
** MusicTimer.c manages the timer device.
** Time is kept in a double floating-point number in seconds.
** Notes starting times are noted and when their length has passed
** they are stopped.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 26-MAR-1990
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
** 8 DEC 91 T. Janzen conform to SAS/C 5.10b remove extern from functs
** 4 Jan 92 TEJ last changes for 2.0
**--
*/
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <exec/interrupts.h>
#include <exec/ports.h>
#include <exec/libraries.h>
#include <exec/tasks.h>
#include <exec/io.h>
#include <exec/devices.h>
#include <devices/timer.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/mathffp.h>
#include <proto/intuition.h>
#include "Window.h"
#include "MusicTimer.h"
struct Library *TimerBase;
static struct timerequest *tr;
extern struct IORequest *CreateExtIO();
extern struct timerequest *CreateTimer(ULONG unit);
static void delete_timer(struct timerequest *);
struct timerequest *CreateTimer(ULONG unit)
/*
** FUNCTIONAL DESCRIPTION:
** Connects this process to a timer device
**
** RETURN VALUE:
** description:
** data_type: pointer to timerequest
**
** ARGUMENTS:
**
** unit-
** description:
** data_type: ULONG
** access: read only
**
** DESIGN:
** ROUTINE
** : timerport = CreatePort()
** : IF failed
** : : return NULL
** : ENDIF
** : timermsg = CreateExtIO()
** : IF failed
** : : return NULL
** : ENDIF
** : OpenDevice()
** : IF failed
** : : delete_timer()
** : : return NULL
** : ENDIF
** : return timermsg
** ENDROUTINE
*/
{
auto int error;
auto struct MsgPort *timerport;
auto struct timerequest *timermsg;
timerport = CreatePort(NULL, 0);
if (NULL == timerport)
{
return NULL;
}
timermsg = (struct timerequest *)
CreateExtIO(timerport, sizeof(struct timerequest));
if (NULL == timermsg)
{
return NULL;
}
error = OpenDevice(TIMERNAME, unit, (struct IORequest *)timermsg, 0L);
if (error != 0)
{
delete_timer(timermsg);
return NULL;
}
return timermsg;
}
int start_timer(void)
/*
** FUNCTIONAL DESCRIPTION:
** Begin using the timer device
**
** RETURN VALUE:
** description:
** data_type: int
**
** DESIGN:
** ROUTINE
** : tr = CreateTimer(UNIT_MICROHZ)
** : IF failed
** : : return -1
** : ENDIF
** : TimerBase = tr->tr_node.io_Device
** : return 0
** ENDROUTINE
*/
{
/*
** start the timer at the beginning of the program
*/
tr = CreateTimer(UNIT_MICROHZ);
if (NULL == tr)
{
return -1;
}
TimerBase = (struct Library *)tr->tr_node.io_Device;
return 0;
}
void remove_timer(void)
/*
** FUNCTIONAL DESCRIPTION:
** Delete the timer device connection
*/
{
/*
** delete the timer at end of program
*/
delete_timer(tr);
return;
}
static void delete_timer(struct timerequest *tr)
/*
** FUNCTIONAL DESCRIPTION:
** Really delete a connection to the timer device
**
** ARGUMENTS:
**
** tr-
** description:
** data_type: pointer to timerequest
** access: read/write only
**
** DESIGN:
** ROUTINE
** : IF tr is valid
** : : get timer port
** : : IF timer port is valid
** : : : DeletePort(tp)
** : : ENDIF
** : : IF tr is valid
** : : : CloseDevice(tr)
** : : ENDIF
** : : DeleteExtIO(tr)
** : ENDIF
** ENDROUTINE
*/
{
auto struct MsgPort *tp;
if (tr != NULL)
{
tp = tr->tr_node.io_Message.mn_ReplyPort;
if (tp != NULL)
{
DeletePort(tp);
}
if (tr != NULL)
{
CloseDevice((struct IORequest *)tr);
}
DeleteExtIO((struct IORequest *)tr, sizeof(struct timerequest));
}
return;
}